package com.pb.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class MyServlet
 */
@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("=======");
		String username=request.getParameter("username");//可以拿到json数据
	    System.out.println("username: "+username);
	    //连接数据库  进行用户名字的查询
	    //也要响应成json形式的数据
	    response.setContentType("text/json; charset=utf-8");//设置响应的数据格式
		 PrintWriter out = response.getWriter();
		// JSONObject jsonobj = new JSONObject(); 
		 //jsonobj.put("response", "success"); // {"response":"success"} 
		// jsonobj.put("msg", "ok");
		// out.println(jsonobj);	
		 
		 out.print("{\"response\":\"success\"}");
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
